class SessionsController < ApplicationController
  skip_before_filter :logado?, :only => :create
  def new
    redirect_to new_funcionario_path
  end

  def create
    user = Funcionario.authenticate(params[:cpf], params[:senha])
    if user
      session[:funcionario_id] = user.id
      redirect_to funcionarios_path, :notice => "Bem-vindo!"
    else
      flash.now.alert = "CPF e/ou senha inválidos."
      render "layouts/index"
    end
  end

  def destroy
    session[:funcionario_id] = nil
    redirect_to root_url, :notice => "Desconectado!"
  end

end
